"use strict";
cc._RF.push(module, '8e981LpNzZGebgxYnwUijIo', 'GameManager');
// script/game/GameManager.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Constants_1 = require("../libs/Constants");
var GameData_1 = require("../libs/GameData");
var HelperMgr_1 = require("../libs/HelperMgr");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GameManager = /** @class */ (function (_super) {
    __extends(GameManager, _super);
    function GameManager() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.player = null;
        _this.stoshs = null;
        _this.sprays = null;
        _this.spray = null;
        /**玩家所在地面 */
        _this.ground = null;
        /**当前力度百分比 */
        _this.forcePercent = 0;
        /**游戏是否开始 */
        _this.gameIsStart = false;
        /**游戏是否结束 */
        _this.gameIsOver = false;
        /*玩家是否打到鱼 */
        _this.playerIsHit = false;
        /*玩家是否正在挥棒 */
        _this.playerIsWave = false;
        /*玩家是否扔出鱼饵 */
        _this.playerIsStosh = false;
        /**游戏击打次数 */
        _this.gameChance = 3;
        /**游戏开始时间 */
        _this.gameStartTime = 60;
        /**游戏运行时间 */
        _this.gameTime = 60;
        /**本关游戏得分 */
        _this.gameScore = 0;
        return _this;
    }
    GameManager_1 = GameManager;
    GameManager.prototype.onLoad = function () {
        GameManager_1.instace = this;
        //预加载分包资源
        cc.assetManager.loadBundle('animation');
        // console.log("当前关卡",GameData.instance.gameStage)
    };
    GameManager.prototype.start = function () {
        if (GameData_1.default.instance.gameBack) {
            this.goon();
        }
        else {
            this.init();
        }
    };
    GameManager.prototype.init = function () {
        var _this = this;
        this.gameIsStart = true;
        this.gameIsOver = false;
        this.playerIsHit = false;
        this.playerIsWave = false;
        this.playerIsStosh = false;
        this.gameScore = 0;
        this.gameChance = 3;
        this.gameStartTime = new Date().valueOf();
        if (!GameData_1.default.instance.gameModel) {
            this.schedule(function () {
                _this.gameTime = Math.floor(Constants_1.default.CrazyGameTime - (new Date().valueOf() - _this.gameStartTime) / 1000);
                if (_this.gameTime < 0 && !_this.gameIsOver && !_this.playerIsHit && !_this.playerIsWave) {
                    _this.gameOver();
                }
            }, 1);
        }
    };
    GameManager.prototype.goon = function () {
        GameData_1.default.instance.gameBack = false;
        this.gameIsStart = true;
        this.gameIsOver = false;
        this.playerIsHit = false;
        this.playerIsWave = false;
        this.playerIsStosh = false;
        this.gameScore = GameData_1.default.instance.gameScore;
        this.gameChance = GameData_1.default.instance.gameChance;
    };
    GameManager.prototype.update = function (dt) {
        if (this.gameIsStart && !this.gameIsOver) {
            GameData_1.default.instance.playScore = this.gameScore;
            if (GameData_1.default.instance.gameModel && this.gameChance <= 0 && !this.playerIsHit && !this.playerIsWave) {
                this.gameOver();
            }
        }
    };
    GameManager.prototype.createSpray = function (pos) {
        var spray = cc.instantiate(this.spray);
        spray.setParent(this.sprays);
        spray.setPosition(pos);
        cc.tween(spray).to(1, { scaleX: 3, scaleY: 3, opacity: 0 }).call(function () {
            spray.destroy();
        }).start();
    };
    GameManager.prototype.gameOver = function () {
        this.gameIsStart = false;
        this.gameIsOver = true;
        HelperMgr_1.default.showUI(Constants_1.default.UIName.UIOver);
    };
    GameManager.prototype.backMain = function () {
        //判断是否是正常游戏模式
        if (GameData_1.default.instance.gameModel) {
            //判定是否是中途退出游戏
            if (!this.gameIsOver) {
                //是中途退出的，记录数据
                GameData_1.default.instance.gameBack = true;
                GameData_1.default.instance.gameScore = this.gameScore;
                GameData_1.default.instance.gameChance = this.gameChance;
            }
            else {
                GameData_1.default.instance.gameBack = false;
            }
        }
        cc.director.loadScene("index");
    };
    var GameManager_1;
    GameManager.instace = null;
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "player", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "stoshs", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "sprays", void 0);
    __decorate([
        property(cc.Prefab)
    ], GameManager.prototype, "spray", void 0);
    GameManager = GameManager_1 = __decorate([
        ccclass
    ], GameManager);
    return GameManager;
}(cc.Component));
exports.default = GameManager;

cc._RF.pop();